package com.example.service1.common.api;


import com.example.service1.common.api.entity.ResponseResult;
import com.example.service1.common.api.fallback.Service1Fallback;
import com.example.service1.common.config.FeignConfig;
import com.example.service1.common.dto.FileTestDto;
import com.example.service1.common.dto.TestDto;
import com.example.service1.common.vo.TestVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 当没有与sentinel配合使用时才生效
 * configuration:该feignClient专属的配置
 * fallback：指定Service1的实现类，并且该实现类是注入容器的
 */
@FeignClient(value = "service1-app",path = "/service1",configuration = FeignConfig.class,
        fallback = Service1Fallback.class)
//@RequestMapping("/service1")//应该在FeignClient的path指定
public interface Service1 {


    @GetMapping("/get/noArg")
    ResponseResult<TestVo> noArgGet();

    @GetMapping("/get/pathArg/{name}/{date}")
    ResponseResult<TestVo> pathArgGet(@PathVariable("name")String name,
                                      @DateTimeFormat(pattern = "yyyy-MM-dd") @PathVariable("date")LocalDate date);

    @PostMapping(value = "/post/pathAndBodyArg/{name}/{date}",consumes = MediaType.APPLICATION_JSON_VALUE)
    ResponseResult<TestVo> pathAndBodyArgPost(@PathVariable("name")String name,
                                              @DateTimeFormat(pattern = "yyyy-MM-dd") @PathVariable("date")LocalDate date,
                                              @RequestBody TestDto dto);

    @PutMapping("/put/pathAndBodyArg/{name}/{date}")
    ResponseResult<TestVo> pathAndBodyArgPut(@PathVariable("name")String name,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd") @PathVariable("date")LocalDate date,
                                             @RequestBody TestDto dto);

    @PostMapping("/post/file/{e}")
    ResponseResult<TestVo> pathAndBodyArgAndFileArgPost(@PathVariable("e") String e,
                                                        @RequestBody FileTestDto fileTestDto);
}
